<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
<!--<base href="http://test.youxiduo.com/iweb/shixin_of_July/" />-->
<base href="http://resource.youxiduo.com/special/shihou/promoter/3324/" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width,user-scalable=no">
<title>老主播回归播一小时=2元</title>
<meta name="keywords" content="游戏多">
<meta name="description" content="游戏多">
<link rel="stylesheet" href="static/css/base.css" />
<link rel="stylesheet" href="static/css/reset.css" />
<link rel="stylesheet" href="static/css/jquery-weui.css" />
<link rel="stylesheet" href="static/css/style.css" />
<script src="static/js/jquery-1.7.1.min.js"></script>
<script src="static/js/zepto.min.js"></script>
<script src="static/js/jquery-weui.js"></script>
<script src="static/js/config.js" ></script>
<script src="static/js/util.js" ></script>
<script language="JavaScript">
	var util;
	var config;
	var baseUrl;
	var baseUrlWage;
	$(function() {
		util = new Util();
		config = new Config();
		baseUrl = config.baseUrl;
		baseUrlWage = config.baseUrlWage;
		var time = 3;
		jQuery.support.cors = true;
		$(".share").click(function() {
			if(from_user_id == "0") {
				$("#login").fadeIn(200);
				//setTimeout('$(".pop").hide()', time * 1000);
				setTimeout('$("#login").hide();window.location.href="shihoutv://route?jump_type=120";', time*1000);
			} else {
				var web_share = {
					"qq": {
						"url": share_url,
						"img": share_icon,
						"title": share_title,
						"subtitle": share_desc
					},
					"wx_person": {
						"url": share_url,
						"img": share_icon,
						"title": share_title,
						"subtitle": share_desc
					},
					"wx_group": {
						"url": share_url,
						"img": share_icon,
						"title": share_title,
						"subtitle": share_desc
					},
					"wb": {
						"url": share_url,
						"img": share_icon,
						"title": share_title,
						"subtitle": share_desc
					}
				};

				if(typeof(window.lion) != "undefined" && typeof(window.lion.web_share) == 'function') {
					window.lion.web_share(JSON.stringify(web_share));
				}
			}
		});

		$('.loginBtn').click(function(){
			if(from_user_id=="0"){
				$(".pop").fadeIn(200);
				setTimeout('$(".pop").hide();window.location.href="shihoutv://route?jump_type=120";', time*1000);
			}
		});
		
		//展开隐藏
		$(".box").each(function() {
			var btnShow = $(this).find(".btnShow");
			var btnHide = $(this).find(".btnHide");
			var rule = $(this).find(".rule");
			btnShow.bind("click", function() {
				rule.css('display', 'block');
				btnShow.css('display', 'none');
				btnHide.css('display', 'block');
			});
			btnHide.bind("click", function() {
				///rule.slideUp();
				rule.css('display', 'none');
				btnHide.css('display', 'none');
				btnShow.css('display', 'block');
			});
		});
		
		$("#btn_sign").click(function(){
			if("1"==signed){
				return;
			}
			if(from_user_id=="0"){
				$("#login_error").fadeIn(200);
				setTimeout('$("#login_error").hide()', time*1000);
			}else{
				signUp(); //报名操作
			}
		});
		
		//点击【立即报名】
		$('.btnBm').live("click", function(){
			signUp();
		});

	});
	
	//报名操作
	function signUp(){
		$.ajax({
			url: baseUrl+"/ajax_sign_up",
			type: 'GET',
			async: false,
			dataType: "jsonp",
			jsonp: "callback", //服务端用于接收callback调用的function名的参数(请使用callback或jsonp)
			jsonpCallback: "success_jsonpCallback", //callback的function名称
			data: {'from_user_id':from_user_id,"share_conf_id":share_conf_id, "deviceId":deviceId},
			success: function (data)
			{
				if(0==data.errorCode){//报名成功
					$("#sign_up_success").fadeIn(200);		
					setTimeout('$("#sign_up_success").hide()', 1500);
					setTimeout('location.href=location.href', 1500);
					//将【立即报名】替换为【个人中心】
					//$(".btnBm").hide();
					//$(".btnOver").css("display","block");
				}
				else{//报名失败
					$("#sign_up_error").html(data.errorDescription);
					$("#sign_up_error").fadeIn(200);
					setTimeout('$("#sign_up_error").hide()', 3000);
				}
			}
		});
	}

	//获取用户信息
	function getUserInfo(){
		console.log('获取用户信息');
		
		$.ajax({
			url: baseUrl+'/UserInfoAjaxApiServlet',
			type: 'GET',
			async: false,
			dataType: "jsonp",
			jsonp: "callback", //服务端用于接收callback调用的function名的参数(请使用callback或jsonp)
			jsonpCallback: "success_jsonpCallback", //callback的function名称
			data: {'userId':from_user_id,"plantId":plan_Id, "activityId":share_conf_id, "deviceId":deviceId},
			success: function (res)
			{
				console.log(res);
				if(res.errorCode == '0'){
					var data = res.result;
					var kaiboTimeStr = data.kaiboTimeStr;
					var income = data.income;
					if(typeof(data.kaiboTimeStr) == "undefined" && kaiboTimeStr.length < 1)
						kaiboTimeStr = "无";
					if(typeof(data.income) == "undefined" && income.length < 1)
						income = "0";
				    var baoming = '<a href="javascript:void(0)" class="btnBm btnZj" title="立即报名"><img src="static/img/btnBm.png" /></a>';
				    if("1" == signed){//已报名
						baoming = '<a href="'+ baseUrl+'/task/user_center?uid='+from_user_id+'&plantId='+plan_Id +'&activityId='+share_conf_id+'" title="我的收益"><span class="btnOver btnZj" style="display:none1;" title="我的收益"><img src="static/img/btnSy.png" /></span></a>';
					}

				    var html = '<div class="userInfo">'+
					            	'<span class="userHead"><img src="'+data.icon+'" /></span>'+
					                '<span class="userName">'+data.nickName+'</span>'+
					                '<span class="userTime">时长：<i>'+kaiboTimeStr+'</i></span>'+
					                '<span class="userMoney">总收益：<i>'+income+'元</i></span>'+
					                baoming+
					            '</div>';
			    	$(".state").prepend(html);
				}
			},
			error:function(res){
				console.log(JSON.stringify(res));
			}
		});
	}
	function success_jsonpCallback(){
	}
	
	//获取用户排名
	function getUserRank(){
		var url = baseUrlWage+'/UserRankAndExtra';
		var dateStr = $('#time').val().split(" ")[0];
		var data = {"activityId":config.activityId, "userId":from_user_id, "startDate":dateStr, "endDate":dateStr};
		var str = "获取用户排名";
		util.log(str);
		util.requestRemoteDate(url, data, function(res){
			util.logResult(str, res);
			if(res.errorCode == "0"){
				var result = res.result;
				var rank = result.rank;
				var wage = result.shiya;
				var viewStatus = result.viewStatus;
				var viewTotal = result.viewTotal;
				
				if(parseInt(rank) > parseInt(viewTotal)){
					rank = "0";
					wage = "0";
				}
				if(rank == "0")
					rank = "无";
				else
					rank += "名";
				if(wage == "0")
					wage = "无";
				else
					wage = (parseInt(wage)/20) + "元"
				$('#rank').html(rank);
				$('#wage').html(wage);
				if(viewStatus == "1"){
					$('.nav').show();
				}
			}
		});
	}
	
</script>
</head>

	<body>

		<div class="wrap">
			<img src="static/img/top1.jpg" />
			<section>
				<!---个人中心--->
				<div class="state">
					<!--<div class="userInfo">
						<span class="userHead"><img src="static/img/shHead.jpg" /></span>
						<span class="userName">小狮子小狮子小狮子</span>
						<span class="userTime">时长：<i>10小时</i></span>
						<span class="userMoney">时薪：<i>50元</i></span>
						<a class="btnBm btnZj" style="display:none;" title="立即报名"><img src="static/img/btnBm.png" /></a>
						<span class="btnOver btnZj" style="display:block;" title="我的收益"><img src="static/img/btnSy.png" /></span>
					</div>-->
					<div class="nav" style="display: none;">
						<p class="navSj g-auto">时间:
							<input class="weui_input" id="time" type="text" value="2017-06-27 00:00">
							<input type="text" value="2017-06-27" class="dispaly_value" />
							<span></span></p>
						<p class="navPm">排名:<i id="rank">1000名</i></p>
						<p class="navJl">奖励:<i id="wage">无</i></p>
					</div>
				</div>
				<!---未登录ios--->
				<div class="noLogin" style="display:none;"><img src="static/img/noLogin.png" /></div>
				<!---分享--->
	            <div class="fcb">
	             <a class="share sharebtn sharebL"><img src="static/img/share.png" /></a>
	                <a href="http://m.shihou.tv/event_share/3233" class="sharebtn sharebR"><img src="static/img/ckjl.png" /></a>
	            </div>
				<div class="header">
					<img src="static/img/bg1.png" />
					<a href="http://m.shihou.tv/event_share/3296" class="rzBtn"><img src="static/img/btn2.png" /></a>
				</div>

				<div class="box">
					<div class="header">
						<img src="static/img/bg2.png" />
						<img src="static/img/bg2-2.png" />
						<a href="http://m.shihou.tv/get_income_tos" class="tx"><img src="static/img/tx.png" /></a>
					</div>
					<div class="rule"><img src="static/img/rule1.png" /></div>
					<a class="btnShow btn"><img src="static/img/btnShow.png" /></a>
					<a class="btnHide btn"><img src="static/img/btnHide.png" /></a>
				</div>
				<!--如何认证-->
				<div class="box">
					<img src="static/img/bg3.png" />
					<a style="bottom:19%;" href="http://m.shihou.tv/event_share/3257" class="rzBtn"><img src="static/img/rz.png" /></a>
				</div>
				<!--推荐有礼-->
				<div class="box">
					<div class="header">
						<img src="static/img/bg4.png" />
						<a class="share xj"><img src="static/img/xj.png" /></a>
					</div>
					<div class="rule"><img src="static/img/rule2.png" /></div>
					<a class="btnShow btn"><img src="static/img/btnShow2.png" /></a>
					<a class="btnHide btn"><img src="static/img/btnHide.png" /></a>
				</div>
				<div class="box">
					<img src="static/img/bg5.png" />
				</div>
			</section>
			<footer><img src="static/img/footer.jpg" /></footer>
		</div>
		<!-- 登录 -->
		<div id="login" class="pop">请登录后再来参加活动吧~</div>
	    <div id="sign_up_success" class="pop">报名成功</div>
		<div id="sign_up_error" class="pop">报名失败,请重试</div>
		<div id="login_error" class="pop">请登录后，再点击分享</div>

	</body>

</html>
<script>
	var share_icon="http://resource.youxiduo.com/special/shihou/promoter/46/static/img/wzry.png";
	var share_title="王者荣耀玩家专属福利";
	var share_desc="立领200元现金！分享再送30元，还不快来！";
	var plan_Id="4PLwi6yLVak6";
	var share_conf_id="41";
	var signed="0";
	var deviceId="243";
	var share_open="1";
	var from_user_id="244269";//244269
	var share_url="http://m.shihou.tv/event_share/41?type=1&page=1&from_user_id=244272&share_config_id=41";
</script>
<script>
	$(function(){
		$('.dispaly_value').val(util.getNowFormatDate(0, 0, -1));
		$("#time").val(util.getNowFormatDate(0, 0, -1) + " 00:00");
		//日历
		$("#time").datetimePicker({
			min: "2017-06-27",
			max: "2017-12-31 23:59",
			//defaultDate: $.datepicker.parseDate("d m", day+" "+month)
		});
		
		if(from_user_id == 0 || from_user_id == '0'){//未登录
			$('.noLogin').show();
		}else{//已登录
			$('.noLogin').hide();
			getUserInfo();
			getUserRank();
		}
		
		//选择好时间后点击【确定】按钮
		$('.close-picker').live("click", function(){
			getUserRank();
		});
		
	});
</script>